﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _05_Time_TrackBar
{
    public partial class Form1 : Form
    {
        //定义数组用来存储图片的路径
        string[] ImageURL = null;
        //定义一个变量用来存储当前图片的索引
        int index = 0;

        public Form1()
        {
            InitializeComponent();
            //读取图片下的所有路径
            ImageURL = System.IO.Directory.GetFiles(@"./xing");
            this.trackBar1.Value = this.timer1.Interval;
            this.label2.Text = this.trackBar1.Value+ "MS";
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            this.label2.Text = this.trackBar1.Value+ "MS";
            this.timer1.Interval = this.trackBar1.Value;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (index < ImageURL.Length - 1)//判断是否达到了最大值，如果没有达到就下一个
            {
                //ImageLocation:设置控件读取图像的路径
                this.pictureBox1.ImageLocation = ImageURL[++index];
            }
            else
            {
                index = 0;
                this.pictureBox1.ImageLocation = ImageURL[index];
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
        }
    }
}
